A r t i c l e s
Navigation

Note: This site is
a bit older, personal views
may have changed.

M a i n P a g e

D i r e c t o r y

Export Functions from Executables


Clearing some myths up, and information on exporting a function from an executable.
In Win32, there are several myths floating about. One myth was that EXE's cannot export functions from executables. Rubbish!
You can export functions from executables in Win32. Supposedly, it was not possible in some pre-386 16-bit versions of windows.
To repeat: yes, you can export stdcall or any sort of functions and procedures from an exe. You can call and use these functions from the exe. Be careful about recursion, but generally it shouldn't get in your way if your design is thought out. For example, an exe can loadlibrary() and the library that was loaded can call exe functions too, after it has been unloaded. Since the exe is already running, you don't have to loadlibrary() on the exe, you just have to define stdcall static functions.
In GnuLinux, can an Elf (linux executable) export functions? Yes. The -E option must be specified when calling the linker (LD). LD options can be tacked on to the -k option when using freepascal (-kE). In Lazarus IDE, there is a compiler options/linker tab which let's you set up the -k parameter. Unfortunately, linking from executables with freepascal is not quite working yet until some patches are made to the compiler. (as of Aug-02-2005)
To repeat: yes, you can export stdcall or any sort of functions and procedures from an ELF executable.
There is very little verbose information on this topic (some info in the linux MAN pages for C programmers), but it is a very powerful and unknown software practise to some people. man dlsym and man dlopen tell us that if you specify nil as the paramater when calling dlopen(), and then you use this gotten handle with dlsym(), you can get the handle to the elf executable which holds your exported functions.
You may not see the need for exporting a function from an executable, however it can be a very powerful feature if you need your DLL/SO to talk more directly with and to the EXE/ELF. There are many situations where you have communication one way, but you also need it the other. The EXE/ELF and DLL/SO should both be like a server, not one just being the client! There are many situations where a DLL/SO needs to talk back to the EXE/ELF in plug-in systems for example. Without two-way communication (two way importing) you just don't have very much power.
Subject: Export function from exe, export functions from exes, exporting a function from an exe, exporting functions from exe's, exporting functions from and elf, export function from elf, export a function from an elf, export functions from elfs, elf vs so, so vs elf, elfs vs shared object libraries, shared objects vs elfs.

About
This site is about programming and other things.
_ _ _